.class public Lorg/microemu/midp/media/audio/PCTone;
.super Ljava/lang/Object;
.source "PCTone.java"


# static fields
.field private static final MAX_TIME:I = 0x4

.field private static final audioFormat:Ljavax/sound/sampled/AudioFormat; = null

.field private static final bigEndian:Z = true

.field private static final channels:I = 0x1

.field static class$javax$sound$sampled$SourceDataLine:Ljava/lang/Class; = null

.field private static final dataLineInfo:Ljavax/sound/sampled/DataLine$Info; = null

.field private static final sampleRate:I = 0x3e80

.field private static final sampleSizeInBits:I = 0x10

.field private static final signed:Z = true


# instance fields
.field private final audioData:[B


# direct methods
.method static constructor <clinit>()V
    .locals 6

    .prologue
    const/4 v3, 0x1

    .line 54
    new-instance v0, Ljavax/sound/sampled/AudioFormat;

    const/high16 v1, 0x467a

    const/16 v2, 0x10

    move v4, v3

    move v5, v3

    invoke-direct/range {v0 .. v5}, Ljavax/sound/sampled/AudioFormat;-><init>(FIIZZ)V

    sput-object v0, Lorg/microemu/midp/media/audio/PCTone;->audioFormat:Ljavax/sound/sampled/AudioFormat;

    .line 62
    new-instance v0, Ljavax/sound/sampled/DataLine$Info;

    sget-object v1, Lorg/microemu/midp/media/audio/PCTone;->class$javax$sound$sampled$SourceDataLine:Ljava/lang/Class;

    if-nez v1, :cond_0

    const-string v1, "javax.sound.sampled.SourceDataLine"

    invoke-static {v1}, Lorg/microemu/midp/media/audio/PCTone;->class$(Ljava/lang/String;)Ljava/lang/Class;

    move-result-object v1

    sput-object v1, Lorg/microemu/midp/media/audio/PCTone;->class$javax$sound$sampled$SourceDataLine:Ljava/lang/Class;

    :goto_0
    sget-object v2, Lorg/microemu/midp/media/audio/PCTone;->audioFormat:Ljavax/sound/sampled/AudioFormat;

    invoke-direct {v0, v1, v2}, Ljavax/sound/sampled/DataLine$Info;-><init>(Ljava/lang/Class;Ljavax/sound/sampled/AudioFormat;)V

    sput-object v0, Lorg/microemu/midp/media/audio/PCTone;->dataLineInfo:Ljavax/sound/sampled/DataLine$Info;

    return-void

    :cond_0
    sget-object v1, Lorg/microemu/midp/media/audio/PCTone;->class$javax$sound$sampled$SourceDataLine:Ljava/lang/Class;

    goto :goto_0
.end method

.method public constructor <init>()V
    .locals 1

    .prologue
    .line 70
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 67
    const v0, 0xfa00

    new-array v0, v0, [B

    iput-object v0, p0, Lorg/microemu/midp/media/audio/PCTone;->audioData:[B

    .line 71
    return-void
.end method

.method static class$(Ljava/lang/String;)Ljava/lang/Class;
    .locals 2
    .parameter "x0"

    .prologue
    .line 64
    :try_start_0
    invoke-static {p0}, Ljava/lang/Class;->forName(Ljava/lang/String;)Ljava/lang/Class;
    :try_end_0
    .catch Ljava/lang/ClassNotFoundException; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v1

    return-object v1

    :catch_0
    move-exception v0

    .local v0, x1:Ljava/lang/ClassNotFoundException;
    new-instance v1, Ljava/lang/NoClassDefFoundError;

    invoke-direct {v1}, Ljava/lang/NoClassDefFoundError;-><init>()V

    invoke-virtual {v1, v0}, Ljava/lang/NoClassDefFoundError;->initCause(Ljava/lang/Throwable;)Ljava/lang/Throwable;

    move-result-object v1

    throw v1
.end method


# virtual methods
.method public play(DDD)V
    .locals 22
    .parameter "frequency"
    .parameter "duration"
    .parameter "volume"

    .prologue
    .line 77
    :try_start_0
    new-instance v8, Ljava/io/ByteArrayInputStream;

    move-object/from16 v0, p0

    iget-object v0, v0, Lorg/microemu/midp/media/audio/PCTone;->audioData:[B

    move-object/from16 v18, v0

    move-object v0, v8

    move-object/from16 v1, v18

    invoke-direct {v0, v1}, Ljava/io/ByteArrayInputStream;-><init>([B)V

    .line 80
    .local v8, byteArrayInputStream:Ljava/io/InputStream;
    new-instance v7, Ljavax/sound/sampled/AudioInputStream;

    sget-object v18, Lorg/microemu/midp/media/audio/PCTone;->audioFormat:Ljavax/sound/sampled/AudioFormat;

    move-object/from16 v0, p0

    iget-object v0, v0, Lorg/microemu/midp/media/audio/PCTone;->audioData:[B

    move-object/from16 v19, v0

    move-object/from16 v0, v19

    array-length v0, v0

    move/from16 v19, v0

    sget-object v20, Lorg/microemu/midp/media/audio/PCTone;->audioFormat:Ljavax/sound/sampled/AudioFormat;

    invoke-virtual/range {v20 .. v20}, Ljavax/sound/sampled/AudioFormat;->getFrameSize()I

    move-result v20

    div-int v19, v19, v20

    move/from16 v0, v19

    int-to-long v0, v0

    move-wide/from16 v19, v0

    move-object v0, v7

    move-object v1, v8

    move-object/from16 v2, v18

    move-wide/from16 v3, v19

    invoke-direct {v0, v1, v2, v3, v4}, Ljavax/sound/sampled/AudioInputStream;-><init>(Ljava/io/InputStream;Ljavax/sound/sampled/AudioFormat;J)V

    .line 86
    .local v7, audioInputStream:Ljavax/sound/sampled/AudioInputStream;
    sget-object v18, Lorg/microemu/midp/media/audio/PCTone;->dataLineInfo:Ljavax/sound/sampled/DataLine$Info;

    invoke-static/range {v18 .. v18}, Ljavax/sound/sampled/AudioSystem;->getLine(Ljavax/sound/sampled/Line$Info;)Ljavax/sound/sampled/Line;

    move-result-object v17

    check-cast v17, Ljavax/sound/sampled/SourceDataLine;

    .line 92
    .local v17, sourceDataLine:Ljavax/sound/sampled/SourceDataLine;
    const-wide/high16 v18, 0x4059

    div-double v5, p5, v18

    .line 94
    .local v5, amplify:D
    const-wide v11, 0x40cf400000000000L

    .line 96
    .local v11, d_sampleRate:D
    const-wide v18, 0x40cf400000000000L

    const-wide v20, 0x408f400000000000L

    div-double v20, p3, v20

    mul-double v18, v18, v20

    const-wide/high16 v20, 0x4000

    div-double v18, v18, v20

    move-wide/from16 v0, v18

    double-to-int v0, v0

    move/from16 v16, v0

    .line 97
    .local v16, size:I
    const/4 v14, 0x0

    .local v14, index:I
    :goto_0
    move v0, v14

    move/from16 v1, v16

    if-ge v0, v1, :cond_0

    .line 99
    move v0, v14

    int-to-double v0, v0

    move-wide/from16 v18, v0

    const-wide v20, 0x40cf400000000000L

    div-double v9, v18, v20

    .line 101
    .local v9, currentTime:D
    const-wide v18, 0x401921fb54442d18L

    mul-double v18, v18, p1

    mul-double v18, v18, v9

    invoke-static/range {v18 .. v19}, Ljava/lang/Math;->sin(D)D

    .line 97
    add-int/lit8 v14, v14, 0x1

    goto :goto_0

    .line 108
    .end local v9           #currentTime:D
    :cond_0
    sget-object v18, Lorg/microemu/midp/media/audio/PCTone;->audioFormat:Ljavax/sound/sampled/AudioFormat;

    const v19, 0xfa00

    move-object/from16 v0, v17

    move-object v1, v7

    move-object/from16 v2, v18

    move/from16 v3, v19

    invoke-static {v0, v1, v2, v3}, Lorg/microemu/midp/media/audio/PCToneRunnablePoolFactory;->getInstance(Ljavax/sound/sampled/SourceDataLine;Ljavax/sound/sampled/AudioInputStream;Ljavax/sound/sampled/AudioFormat;I)Lorg/microemu/midp/media/audio/PCToneRunnable;

    move-result-object v15

    .line 115
    .local v15, pcToneRunnable:Lorg/microemu/midp/media/audio/PCToneRunnable;
    new-instance v18, Ljava/lang/Thread;

    move-object/from16 v0, v18

    move-object v1, v15

    invoke-direct {v0, v1}, Ljava/lang/Thread;-><init>(Ljava/lang/Runnable;)V

    invoke-virtual/range {v18 .. v18}, Ljava/lang/Thread;->start()V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .line 121
    .end local v8           #byteArrayInputStream:Ljava/io/InputStream;
    .end local v7           #audioInputStream:Ljavax/sound/sampled/AudioInputStream;
    .end local v17           #sourceDataLine:Ljavax/sound/sampled/SourceDataLine;
    .end local v5           #amplify:D
    .end local v11           #d_sampleRate:D
    .end local v16           #size:I
    .end local v14           #index:I
    .end local v15           #pcToneRunnable:Lorg/microemu/midp/media/audio/PCToneRunnable;
    :goto_1
    return-void

    .line 117
    :catch_0
    move-exception v18

    move-object/from16 v13, v18

    .line 119
    .local v13, e:Ljava/lang/Exception;
    invoke-virtual {v13}, Ljava/lang/Exception;->printStackTrace()V

    goto :goto_1
.end method
